export const loadScript = (src: string): Promise<void> => {
  // 防止重复加载
  if (document.querySelector(`script[src="${src}"]`)) {
    return Promise.resolve()
  }

  return new Promise((resolve, reject) => {
    const script = document.createElement('script')
    script.src = src
    script.onload = () => resolve()
    script.onerror = () => reject(new Error(`加载脚本失败: ${src}`))
    document.body.appendChild(script)
  })
}